﻿/*
*┌────────────────────────────────────────────────┐
*│　描    述：AppConfig                                                   
*│　作    者： (Jxw)                                             
*│　版    本：1.0     
*│　功能描述：                                          
*│　创建时间：2021/4/20 10:10:36                        
*└────────────────────────────────────────────────┘
*/

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Utility
{

    public class AppConfig
    {
        /// <summary>
        /// 数据库连接
        /// </summary>
        public static readonly string ConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
        public static readonly string MainConnString = ConfigurationManager.ConnectionStrings["MainConnString"].ConnectionString;
        public static readonly string QueryMainConnString = ConfigurationManager.ConnectionStrings["QueryMainConnString"].ConnectionString;


        private static string m_HttpIP = GetStringConfigValue("HttpIP");
        /// <summary>
        ///http监听地址
        /// </summary>
        public static string HttpIP
        {
            get { return m_HttpIP; }
        }


         private static string m_appCode = GetStringConfigValue("appCode");
        /// <summary>
        ///appcode
        /// </summary>
        public static string appCode
        {
            get { return m_appCode; }
        }

        private static string m_sign = GetStringConfigValue("sign");
        /// <summary>
        ///sign
        /// </summary>
        public static string sign
        {
            get { return m_sign; }
        }
        
        private static string m_DDJJUrl = GetStringConfigValue("DDJJUrl");
        /// <summary>
        ///万达调度急救信息接口url
        /// </summary>
        public static string DDJJUrl
        {
            get { return m_DDJJUrl; }
        }
        
        
        private static string m_JZQueryUrl = GetStringConfigValue("JZQueryUrl");
        /// <summary>
        ///查询极致接口url
        /// </summary>
        public static string JZQueryUrl
        {
            get { return m_JZQueryUrl; }
        }

        private static string m_JZsign = GetStringConfigValue("JZsign");
        /// <summary>
        ///极致接口sign
        /// </summary>
        public static string JZsign
        {
            get { return m_JZsign; }
        }


        private static string m_ZEQueryUrl = GetStringConfigValue("ZEQueryUrl");
        /// <summary>
        ///查询卓尔接口url
        /// </summary>
        public static string ZEQueryUrl
        {
            get { return m_ZEQueryUrl; }
        }


        private static string m_ZEsign = GetStringConfigValue("ZEsign");
        /// <summary>
        ///卓尔接口sign
        /// </summary>
        public static string ZEsign
        {
            get { return m_ZEsign; }
        }


        private static string m_GDNsign = GetStringConfigValue("GDNsign");
        /// <summary>
        ///高迪恩接口sign
        /// </summary>
        public static string GDNsign
        {
            get { return m_GDNsign; }
        }

        private static string m_GDNUrl = GetStringConfigValue("GDNUrl");
        /// <summary>
        ///高迪恩接口url
        /// </summary>
        public static string GDNUrl
        {
            get { return m_GDNUrl; }
        }


        private static string m_HospSortsign = GetStringConfigValue("HospSortsign");
        /// <summary>
        ///高迪恩接口sign
        /// </summary>
        public static string HospSortsign
        {
            get { return m_HospSortsign; }
        }

        private static string m_HospSortUrl = GetStringConfigValue("HospSortUrl");
        /// <summary>
        ///高迪恩接口url
        /// </summary>
        public static string HospSortUrl
        {
            get { return m_HospSortUrl; }
        }



        private static string m_BDApi = GetStringConfigValue("BDApi");
        /// <summary>
        ///BDApi    
        /// </summary>
        public static string BDApi
        {
            get { return m_BDApi; }
        }

        private static string m_BDKey = GetStringConfigValue("BDKey");
        /// <summary>
        ///BDKey
        /// </summary>
        public static string BDKey
        {
            get { return m_BDKey; }
        }


        private static string m_ECGFile = GetStringConfigValue("ECGFile");
        /// <summary>
        ///心电路径
        /// </summary>
        public static string ECGFile
        {
            get { return m_ECGFile; }
        }
        
        private static int m_UploadTime = GetInt32ConfigValue("UploadTime");
        /// <summary>
        ///上传时间间隔
        /// </summary>
        public static int UploadTime
        {
            get { return m_UploadTime; }
        }

        private static int m_TimingTime = GetInt32ConfigValue("TimingTime");
        /// <summary>
        ///定时时间
        /// </summary>
        public static int TimingTime
        {
            get { return m_TimingTime; }
        }



        private static int m_UpLoadMaxDataLength = GetInt32ConfigValue("UpLoadMaxDataLength");
        /// <summary>
        ///上传最大数量
        /// </summary>
        public static int UpLoadMaxDataLength
        {
            get { return m_UpLoadMaxDataLength; }
        }
        
        private static int m_InnerComm = GetInt32ConfigValue("InnerComm");
        /// <summary>
        ///启动内部通信
        /// </summary>
        public static int InnerComm
        {
            get { return m_InnerComm; }
        }


        private static string m_SourceCode = GetStringConfigValue("SourceCode");
        /// <summary>
        ///来源编码
        /// </summary>
        public static string SourceCode
        {
            get { return m_SourceCode; }
        }
        
        private static string m_SourceName = GetStringConfigValue("SourceName");
        /// <summary>
        ///来源名称
        /// </summary>
        public static string SourceName
        {
            get { return m_SourceName; }
        }
         
        private static string m_PurposeCode = GetStringConfigValue("PurposeCode");
        /// <summary>
        ///目的编码
        /// </summary>
        public static string PurposeCode
        {
            get { return m_PurposeCode; }
        }
        
        private static string m_PurposeName = GetStringConfigValue("PurposeName");
        /// <summary>
        ///心电路径
        /// </summary>
        public static string PurposeName
        {
            get { return m_PurposeName; }
        }

        #region 基础方法

        /// <summary>
        /// 获取bool型Config值
        /// </summary>
        /// <param name="keyName">键名称</param>
        /// <returns>键值,yes对应True,其他均为False</returns>
        private static bool GetBoolConfigValue(string keyName)
        {
            Regex regex = new Regex("^yes$", RegexOptions.IgnoreCase);
            string tempStr;
            try
            {
                tempStr = ConfigurationManager.AppSettings[keyName].ToString();
            }
            catch
            {
                tempStr = "no";
            }
            return regex.IsMatch(tempStr);
        }

        /// <summary>
        /// 获取数字型Config值
        /// </summary>
        /// <param name="keyName">键名称</param>
        /// <returns>键值,失败返回0</returns>
        private static Int32 GetInt32ConfigValue(string keyName)
        {
            Regex regex = new Regex("^\\d*$");
            string tempStr;
            try
            {
                tempStr = ConfigurationManager.AppSettings[keyName].ToString();
                if (regex.IsMatch(tempStr))
                {
                    return Convert.ToInt32(tempStr);
                }

                return 0;
            }
            catch
            {
                return 0;
            }
        }

        /// <summary>
        /// 获取字符串型Config值
        /// </summary>
        /// <param name="keyName">键名称</param>
        /// <returns>键值</returns>
        private static string GetStringConfigValue(string keyName)
        {
            try
            {
                return ConfigurationManager.AppSettings[keyName].ToString();
            }
            catch
            {
                return "";
            }
        }

        #endregion

    }
}
